//======================================================
//==                  Motor programer                ===   
//======================================================
//MOTOR(int (+/-)Left_PWM,int (+/-)Right_PWM)
//‘+’电机正转；‘—’电机反转
//PWM:范围0~255
//======================================================
int M_left1 =7;
int M_left2 =6; 
int M_right1 =5; 
int M_right2 =4;
 void Motor(int Left_PWM,int Right_PWM)
 {
   if(Left_PWM != 0)
    {
      if(Left_PWM>0)
      {
        analogWrite(M_left1,Left_PWM);
        digitalWrite(M_left2,LOW);
      }
      else
      {
        digitalWrite(M_left1,LOW);
        analogWrite(M_left2,-Left_PWM);
      }
    }
    else 
    {
        digitalWrite(M_left1,LOW);
        digitalWrite(M_left2,LOW);
    }
    if(Right_PWM != 0)
    {
      if(Right_PWM>0)
      {
        analogWrite(M_right1,Right_PWM);
        digitalWrite(M_right2, LOW); 
      }
      else 
      {
        digitalWrite(M_right1, LOW);
        analogWrite(M_right2, -Right_PWM);
      }
    }
    else
      {
        digitalWrite(M_right1, LOW);
        digitalWrite(M_right2, LOW);
      }
 }
 void setup()
 {
    Serial.begin(115200);
    pinMode(M_left1, OUTPUT); //L298P直流电机驱动板的控制端口设置为输出模式  
    pinMode(M_left2, OUTPUT);
    
    pinMode(M_right1, OUTPUT);
    pinMode(M_right2, OUTPUT); 
 }
 void loop()
 {
   Motor(-200,-200);
 }
